package com.csx.base.design.structure.flyweight;

import java.util.HashMap;
import java.util.Map;

/**
 * @author cuisongxu
 * @date 2022/9/21 12:18
 */
public class TitleFactory {

    /**
     * 图库
     */
    private Map<String, Drawable> images;


    public TitleFactory() {
        this.images = new HashMap<>();
    }

    public Drawable getDrawable(String image) {

        // 缓存池中没有图片，则实例化并放入缓存池中
        if(!images.containsKey(image)) {
           switch (image) {
               case "河流":
                   images.put(image, new River());
                   break;
               case "草地":
                   images.put(image, new Grass());
                   break;
               case "道路":
                   images.put(image, new Stone());
                   break;
               case "房屋":
                   images.put(image, new House());
                   break;
               default:
                   break;
           }
        }
        return images.get(image);
    }
}
